<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心动匹配 - 注册</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/styles.css"> <!-- General styles -->
    <link rel="stylesheet" href="css/theme-styles.css"> <!-- Theme specific styles -->
    <style>
        /* Styles specific to register.html, adapted from login.html */
        /* Body padding for fixed header/footer is handled by theme-styles.css */
        /* This container is inside body, so it should respect body's padding */
        .container { 
             max-width: 500px; 
             margin: 0 auto; /* Centered, body padding will give top/bottom space */
             padding: 1rem; /* Padding for content within this container */
             display: flex;
             flex-direction: column;
             min-height: calc(100vh - 120px); /* Fill available height considering body's top/bottom padding */
             box-sizing: border-box;
        }
        header { /* Basic header structure for register page, not fixed like index.html */
            display: flex;
            justify-content: space-between; 
            align-items: center;
            padding: 10px 0; /* Vertical padding, horizontal alignment by content */
            margin-bottom: 1rem; /* Space below header */
            width: 100%; /* Ensure header takes full width of its container */
        }
        /* .logo will be themed by theme-styles.css */

        .register-container { /* Themed form container, similar to login-container */
            max-width: 450px; /* Slightly narrower for register form */
            margin: 2rem auto; /* Increased top/bottom margin for better spacing */
            padding: 2.5rem; /* Increased padding */
            background: rgba(var(--primary-glow-color-rgb, 196, 113, 237), 0.04); /* Slightly adjusted background */
            border: 1px solid rgba(var(--primary-glow-color-rgb, 196, 113, 237),0.2); /* Slightly stronger border */
            border-radius: 15px; /* More rounded corners */
            box-shadow: 0 8px 30px rgba(var(--primary-glow-color-rgb, 196, 113, 237), 0.1), 0 4px 10px rgba(0,0,0,0.15); /* Softer, themed shadow */
            width: 100%; /* Ensure it takes available width up to max-width */
            box-sizing: border-box;
        }
        
        .register-header {
            text-align: center;
            margin-bottom: 2.5rem; /* Increased margin */
        }
        
        .register-header h1 { /* Themed heading */
            color: var(--primary-glow-color);
            font-size: 2.2rem; /* Slightly larger */
            text-shadow: 0 0 10px rgba(var(--primary-glow-color-rgb, 196, 113, 237), 0.5);
            margin-bottom: 0.75rem; /* Space below h1 */
        }
         .register-header p {
            color: var(--text-glow-color);
            opacity: 0.85; /* Slightly more opaque */
            font-size: 1rem;
        }
        
        .form-group {
            margin-bottom: 1.8rem; /* Increased margin */
        }
        
        .form-group label {
            display: block;
            margin-bottom: 0.6rem; /* Increased margin */
            font-weight: 600;
            color: var(--text-glow-color);
            opacity: 0.9;
            font-size: 0.95rem; /* Slightly adjusted font size */
        }
        
        .theme-active-input { /* Styling for inputs with this class */
            width: 100%;
            padding: 14px 18px; /* Increased padding */
            font-size: 1rem;
            color: var(--text-glow-color);
            background-color: rgba(var(--secondary-glow-color-rgb, 98, 83, 255), 0.08); /* Using secondary color for input bg */
            border: 1px solid rgba(var(--secondary-glow-color-rgb, 98, 83, 255), 0.4); /* Secondary color border */
            border-radius: 8px;
            box-sizing: border-box;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
        }

        .theme-active-input::placeholder {
            color: rgba(var(--text-glow-color-rgb, 240, 217, 255), 0.5);
            opacity: 1; /* Ensure placeholder is visible */
        }

        .theme-active-input:focus {
            outline: none;
            border-color: var(--primary-glow-color);
            box-shadow: 0 0 10px rgba(var(--primary-glow-color-rgb, 196, 113, 237), 0.4);
        }
        
        .btn-register { /* This class is on the button, .theme-active-btn provides base theme */
            width: 100%;
            padding: 14px; /* Increased padding */
            font-size: 1.1rem;
            font-weight: 700; /* Bolder */
            border-radius: 8px; /* Match input fields */
            transition: background-color 0.3s ease, transform 0.2s ease; 
        }
        .btn-register:active {
            transform: scale(0.98); /* Click feedback */
        }
        
        .login-link {
            text-align: center;
            margin-top: 1.5rem;
            font-size: 0.9rem;
        }
        .login-link a { /* Themed links */
            color: var(--secondary-glow-color);
            text-decoration: none;
            transition: color 0.3s;
        }
        .login-link a:hover {
            color: var(--primary-glow-color);
            text-decoration: underline;
        }
    </style>
</head>
<body class="theme-active">
    <div class="tech-beams-background"> <!-- Added for theme consistency -->
        <div class="beam beam-1"></div>
        <div class="beam beam-2"></div>
        <div class="beam beam-3"></div>
        <div class="beam beam-4"></div>
    </div>
    <div class="container">
        <header>
            <div class="logo theme-active-logo">
                <i class="fas fa-heart"></i>
                <span>心动匹配</span>
            </div>
        </header>

        <div class="register-container theme-active-card"> <!-- Added theme-active-card -->
            <div class="register-header">
                <h1>创建账户</h1>
                <p>加入心动匹配，遇见你的缘分</p>
            </div>
            
            <form id="register-form">
                <div class="form-group">
                    <label for="email">邮箱地址</label>
                    <input type="email" id="email" required placeholder="请输入您的邮箱" class="theme-active-input">
                </div>
                
                <div class="form-group">
                    <label for="password">设置密码</label>
                    <input type="password" id="password" required placeholder="至少6位字符" minlength="6" class="theme-active-input">
                </div>
                
                <div class="form-group">
                    <label for="nickname">昵称</label>
                    <input type="text" id="nickname" required placeholder="怎么称呼您？" class="theme-active-input">
                </div>
                
                <button type="submit" class="btn btn-primary btn-register theme-active-btn">注册</button>
            </form>
            
            <div class="login-link">
                <p>已有账户？ <a href="login.html">立即登录</a></p>
            </div>
        </div>
    </div>

    <!-- Floating Action Button for Theme -->
    <button class="fab-theme-button" id="fabThemeButton" aria-label="打开颜色选择器">
        <i class="fas fa-palette"></i>
    </button>

    <!-- Color Drawer -->
    <div class="color-drawer" id="colorDrawer">
        <h4>选择主题颜色</h4>
        <div class="color-options" id="colorOptionsContainer">
            <!-- Color options will be populated by JavaScript -->
        </div>
    </div>

    <script>
        document.getElementById('register-form').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const email = document.getElementById('email').value;
            const password = document.getElementById('password').value;
            const nickname = document.getElementById('nickname').value;
            
            if (!email || !password || !nickname) {
                alert('请填写所有字段');
                return;
            }
            
            if (password.length < 6) {
                alert('密码至少需要6位字符');
                return;
            }
            
            try {
                const response = await fetch('http://14.103.133.136:5000/api/register', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        email: email,
                        password: password,
                        nickname: nickname
                    })
                });
                
                const data = await response.json();
                
                if (response.ok) {
                    alert('注册成功！即将跳转到个人中心完善资料');
                    localStorage.setItem('token', data.token);
                    localStorage.setItem('user_id', data.user_id);
                    localStorage.setItem('nickname', nickname);
                    
                    // 跳转到个人中心页面完善资料
                    window.location.href = 'profile.html';
                } else {
                    alert('注册失败：' + data.message);
                }
            } catch (error) {
                console.error('注册错误:', error);
                alert('网络错误，请检查连接后重试');
            }
        });

        // Theme Switcher Logic
        document.addEventListener('DOMContentLoaded', () => {
            const fabThemeButton = document.getElementById('fabThemeButton');
            const colorDrawer = document.getElementById('colorDrawer');
            const colorOptionsContainer = document.getElementById('colorOptionsContainer');
            const root = document.documentElement;

            if (fabThemeButton && colorDrawer && colorOptionsContainer) { // Ensure elements exist
                function hexToRgb(hex) {
                    const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
                    return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null;
                }

                function setRgbCssVars() {
                    const rootStyles = getComputedStyle(document.documentElement);
                    const primaryGlowHex = rootStyles.getPropertyValue('--primary-glow-color').trim();
                    const secondaryGlowHex = rootStyles.getPropertyValue('--secondary-glow-color').trim();
                    const textGlowHex = rootStyles.getPropertyValue('--text-glow-color').trim();

                    const primaryGlowRgb = hexToRgb(primaryGlowHex);
                    const secondaryGlowRgb = hexToRgb(secondaryGlowHex);
                    const textGlowRgb = hexToRgb(textGlowHex);

                    if (primaryGlowRgb) document.documentElement.style.setProperty('--primary-glow-color-rgb', `${primaryGlowRgb.r},${primaryGlowRgb.g},${primaryGlowRgb.b}`);
                    if (secondaryGlowRgb) document.documentElement.style.setProperty('--secondary-glow-color-rgb', `${secondaryGlowRgb.r},${secondaryGlowRgb.g},${secondaryGlowRgb.b}`);
                    if (textGlowRgb) document.documentElement.style.setProperty('--text-glow-color-rgb', `${textGlowRgb.r},${textGlowRgb.g},${textGlowRgb.b}`);
                }
                setRgbCssVars();

                const themes = [
                    { name: 'Default Purple', primary: '#c471ed', secondary: '#6253FF', text: '#f0d9ff', tip: '#ffffff' },
                    { name: 'Cyber Blue', primary: '#00e0ff', secondary: '#0077ff', text: '#e0f7ff', tip: '#ffffff' },
                    { name: 'Synth Pink', primary: '#ff00aa', secondary: '#c500ff', text: '#ffe0f5', tip: '#ffffff' },
                    { name: 'Emerald Green', primary: '#00ffaa', secondary: '#00aa7f', text: '#e0fff5', tip: '#ffffff' },
                    { name: 'Solar Orange', primary: '#ffaa00', secondary: '#ff7700', text: '#fff5e0', tip: '#ffffff' },
                    { name: 'Ruby Red', primary: '#ff0055', secondary: '#aa003c', text: '#ffe0e8', tip: '#ffffff' }
                ];
                let currentTheme = themes[0];

                function applyTheme(theme) {
                    root.style.setProperty('--primary-glow-color', theme.primary);
                    root.style.setProperty('--secondary-glow-color', theme.secondary);
                    root.style.setProperty('--text-glow-color', theme.text);
                    root.style.setProperty('--fiber-tip-highlight', theme.tip);
                    setRgbCssVars();
                    currentTheme = theme;
                    localStorage.setItem('selectedTheme', JSON.stringify(theme));
                    updateActiveColorOption();
                }

                function loadTheme() {
                    const savedTheme = localStorage.getItem('selectedTheme');
                    if (savedTheme) {
                        applyTheme(JSON.parse(savedTheme));
                    } else {
                        applyTheme(themes[0]);
                    }
                }

                function updateActiveColorOption() {
                    const options = colorOptionsContainer.querySelectorAll('.color-option');
                    options.forEach(opt => {
                        opt.classList.toggle('active', opt.dataset.primary === currentTheme.primary);
                    });
                }

                themes.forEach(theme => {
                    const option = document.createElement('div');
                    option.className = 'color-option';
                    option.dataset.primary = theme.primary;
                    const span = document.createElement('span');
                    span.style.background = `linear-gradient(135deg, ${theme.primary}, ${theme.secondary})`;
                    option.appendChild(span);
                    option.setAttribute('title', theme.name);
                    option.addEventListener('click', () => applyTheme(theme));
                    colorOptionsContainer.appendChild(option);
                });

                fabThemeButton.addEventListener('click', () => colorDrawer.classList.toggle('open'));
                document.addEventListener('click', (event) => {
                    if (!colorDrawer.contains(event.target) && !fabThemeButton.contains(event.target) && colorDrawer.classList.contains('open')) {
                        colorDrawer.classList.remove('open');
                    }
                });
                loadTheme();
            }
        });
    </script>
</body>
</html>
